package reflect;

import java.lang.reflect.Constructor;

public class ReflectDemo4 {
    public static void main(String[] args) throws Exception{
        Class cls=Class.forName("reflect.Person");//获取类对象
        Constructor c=cls.getConstructor();
        Object obj=c.newInstance();
        System.out.println(obj);
        Constructor[]cons=cls.getConstructors();
        System.out.println("一共有"+cons.length+"个构造器");
        Constructor c2=cls.getConstructor(String.class);
        Object obj2=c2.newInstance("张三");
        System.out.println(obj2);
        Constructor c3=cls.getConstructor(String.class,int.class);
        Object obj3=c3.newInstance("李四",20);
        System.out.println(obj3);

    }
}
